<!DOCTYPE HTML>
<html style="background-color:rgb(249,249,251)">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Pairstudents</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/pair.css" />

</head>

<style>
    [v-cloak] {
        display: none;
    }
</style>

<body style="background-color:rgb(249,249,251)">
    <div class="edit" id="edit">
        <span v-cloak v-if="cancel==true" class="edittext1" @click="canceldelete()">取消删除</span> <span v-if="editif==true"
            class="edittext" @click="edit()">编辑</span>
    </div>
    <div class="pictureboxall" v-cloak>
        <div v-for="item in students" class="picturebox" style="float:left">
            <div class="pictureup" style="background-color:rgb(231,169,114);"></div>
            <div class="personimg" style="background-image: url(../image/head.jpg);" @click="changetosfm($index)"></div>
            <div class="message" style="font-size:0.6rem" @click="changetosfm($index)">{{item.name}}</div>
            <div class="message1" style="font-size:0.65rem" @click="changetosfm($index)">{{item.dept.depName}}</div>
            <div class="message2" style="font-size:0.65rem" @click="changetosfm($index)">{{item.phone}}</div>
            <div v-if="ifshow==true" class="delete" @click="delmsg($index)"><img style="width:25px" src="../icon/deletestudent.png"></div>
        </div>
    </div>


</body>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/vue1.0.js"></script>
<script type="text/javascript" src="../script/util.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    apiready = function () {
        vm = new Vue(vueConfig);

        api.addEventListener({
            name: 'viewappear'
        }, function (ret, err) {
            vm.get();
        });

    };

    vueConfig = {
        el: "body",
        data: {
            students: [],
            ifshow: false,
            deletemsg: "删除",
            cancel: false,
            editif: true
        },
        created: function () {
            var me = this;
            me.get();
        },
        methods: {
            get: function () {
                var me = this;
                $api.get(serverIp + '/friend/listMyFriendStudent.do', function (ret) {
                    if (ret) {
                        if (ret.totalCounts > 0) {
                            me.students = ret.result;
                            api.setPrefs({
                                key: 'students',
                                value: me.students
                            });
                        }
                    }
                }, 'json');
            },
            changetosfm: function (index) {
                api.openWin({
                    name: 'StudentInformation',
                    url: './pairStudent/StudentInformation.html',
                    reload: true,
                    pageParam: {
                        index: index
                    }
                });
            },
            delmsg: function (index) {
                var me = this;
                var dialogBox = api.require('dialogBox');
                dialogBox.alert({
                    texts: {
                        title: '确认',
                        content: '您正在删除结对学生',
                        leftBtnTitle: '取消',
                        rightBtnTitle: '确认删除'
                    },
                    styles: {
                        bg: '#fff',
                        w: 300,
                        title: {
                            marginT: 20,
                            titleSize: 14,
                            titleColor: '#000'
                        },
                        content: {
                            color: '#000',
                            size: 14
                        },
                        left: {
                            marginB: 7,
                            marginL: 20,
                            w: 130,
                            h: 35,
                            corner: 2,
                            bg: '#fff',
                            size: 12
                        },
                        right: {
                            marginB: 7,
                            marginL: 10,
                            w: 130,
                            h: 35,
                            corner: 2,
                            bg: 'blue',
                            size: 12
                        }
                    }
                }, function (ret) {
                    if (ret.eventType == 'right') {
                        api.ajax({
                            url: serverIp + "/friend/deleteJieDuiStudent.do",
                            method: 'post',
                            data: {
                                values: {
                                    stu_id: me.students[index].oid
                                }
                            }
                        }, function (ret, err) {
                            if (ret) {
                                alert("删除成功！");
                                me.get();

                            } else {
                                alert("删除失败！" + JSON.stringify(err));
                            }
                            var dialogBox = api.require('dialogBox');
                            dialogBox.close({
                                dialogName: 'alert'
                            });
                        });
                    }
                    if (ret.eventType == 'left') {
                        var dialogBox = api.require('dialogBox');
                        dialogBox.close({
                            dialogName: 'alert'
                        });
                    }
                });
            },
            delete: function () {
                var me = this;
                me.ifshow = true;
                me.cancel = true;
            },
            canceldelete: function () {
                var me = this;
                me.ifshow = false;
                me.cancel = false;
                me.editif = true;
            },
            add: function () {
                var me = this;
                api.openWin({
                    name: 'addstudentmsg',
                    url: './pairStudent/addstudentmsg.html',
                    reload: true
                });
                me.get();
            },
            edit: function () {
                var me = this;
                api.actionSheet({
                    title: '选择编辑类型',
                    cancelTitle: '取消',
                    buttons: ['增加', '删除']
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        me.add();
                    } else if (index == 2) {
                        me.delete();
                        me.editif = false;
                    }
                });
            }
        }
    }
</script>

</html>